import { time } from '../../utils/util'
import { openPage } from '../../utils/map/open'
const app = getApp()
Page({
  data: {
    imgurl: app.globalData.imgurl,
    touchStartTime: 0, // 触摸开始时间
    touchEndTime: 0, // 触摸结束时间
    lastTapTime: 0, // 最后一次单击事件点击发生时间
  },
  onLoad({ gss_id }) {
    this._getDetail(gss_id)
    this._getEaluationlist()
  },
  // 打开导航
  openMap({ timeStamp }) {
    const {
      touchEndTime,
      touchStartTime,
      lastTapTime,
      p_name,
      c_name,
      a_name,
      address,
    } = this.data
    // 控制点击事件在350ms内触发，加这层判断是为了防止长按时会触发点击事件
    if (touchEndTime - touchStartTime < 350) {
      // 更新最后一次点击时间
      this.setData({
        lastTapTime: timeStamp,
      })
      // 如果两次点击时间在300毫秒内，则认为是双击事件
      if (timeStamp - lastTapTime > 300) {
        // do something 点击事件具体执行那个业务
        openPage({ p_name, c_name, a_name, address }, this)
      }
    }
  },
  // 获取详情
  async _getDetail(gss_id) {
    let { code, data } = await wx.requestAsync({
      url: '/game/spell/detail',
      data: {
        gss_id,
      },
    })
    if (code == 0) {
      data.begin_at = time(data.begin_at)
      data.end_at = time(data.end_at)
      this.setData(data)
    }
  },
  // 获取评价内容
  async _getEaluationlist() {
    const { gs_id, s_id } = this.data
    let { code, data } = await wx.requestAsync({
      url: '/evaluate',
      data: {
        page: 1,
        limit: 3,
        type: 1,
        s_id,
        gs_id,
      },
    })
    if (code == 0) {
      this.setData({
        list: data,
      })
    }
  },
  // 评价列表
  _toLink() {
    const { gs_id } = this.data
    let params = {
      type: 1,
      gs_id,
    }
    wx.navigateTo({
      url:
        '/pages/evaluationlist/evaluationlist?params=' + JSON.stringify(params),
    })
  },
  // 提交
  submit() {
    const { gss_id } = this.data
    console.log('点击提交')
    wx.navigateTo({
      url: '/pages/grouporders/grouporders?gss_id=' + gss_id,
    })
  },
  _handleLeft(e) {
    console.log(e)
  },
  _handleRight() {},
})
